﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL
{
    public partial class Facility
    {
        public List<DAL.Facility> getFacilitiesList()
        {
            DAL.ClubEntities club = new DAL.ClubEntities();
            var facilityQuery = from o in club.Facilities
                                where o.IsUnderMaintenance==false
                                select o;
            return facilityQuery.ToList<DAL.Facility>();
        }
        public DAL.Facility getFacility(int id)
        {
            DAL.ClubEntities club = new DAL.ClubEntities();
            var facilityQuery = from o in club.Facilities
                                where o.Id == id
                                && o.IsUnderMaintenance==false
                                select o;
            return facilityQuery.First<DAL.Facility>();
        }
        public DAL.Facility getFacility(string name)
        {
            DAL.ClubEntities club = new DAL.ClubEntities();
            var facilityQuery = from o in club.Facilities
                                where o.Name == name
                                select o;
            return facilityQuery.First<DAL.Facility>();
        }
        public DAL.Facility getFacility()
        {
            DAL.ClubEntities club = new DAL.ClubEntities();
            var facilityQuery = from o in club.Facilities                      
                                select o;
            return facilityQuery.First<DAL.Facility>();
        }
        public void placeBook(DAL.Booking book)
        {
            DAL.ClubEntities club = new DAL.ClubEntities();
            club.Bookings.AddObject(book);
            club.SaveChanges();
        }
    }
}
